<?php
/**
 * Created by PhpStorm.
 * User: aron
 * Date: 2019/5/10
 * Time: 8:09 PM
 */

include_once "../../Util/DebugUtil/DebugUtil.php";

class MyTestExistClass {
    var $var1;
    private $pri_var2;
    public $pub_var3;
    function method1(){

    }

    function existMethod() {

    }
}

class MyTestExistSubClass extends  MyTestExistClass {

}

/***************** 类存在判断；方法、属性存在判断；是否为某种类型判断；获取方法、属性、类名、父类名 ********************/

/***************** class_exists ********************/
DebugUtil::printDebugSeperator("class_exists");
$exist = class_exists("MyTestExistClass");
echo "\$exist = $exist";
yt_debug_print_break_line();

$exist = class_exists("MyUnTestExistClass");
echo "\$exist = $exist";
yt_debug_print_break_line();

/***************** get_class_methods ********************/
DebugUtil::printDebugSeperator("get_class_methods");
$methods = get_class_methods("MyTestExistClass");
foreach ($methods as $method) {
    var_dump($method);
}
print_r($methods);
yt_debug_print_break_line();


/***************** get_class_vars ********************/
DebugUtil::printDebugSeperator("get_class_vars");
$vars = get_class_vars("MyTestExistClass");
foreach ($vars as $key=>$value) {
    var_dump($key);
    var_dump($value);
}
print_r($vars);
// output:
// Array ( [var1] => [pub_var3] => )
yt_debug_print_break_line();


/***************** get_class ********************/
DebugUtil::printDebugSeperator("get_class");
$obj = new MyTestExistClass();
$className = get_class($obj);
echo "\$className = $className\r\n";
var_dump($className);
yt_debug_print_break_line();



/***************** get_object_vars ********************/
DebugUtil::printDebugSeperator("get_object_vars");
$obj = new MyTestExistClass();
$obj->var1 = "var1 value";
$obj->pub_var3 = "pub_var3 value";
$vars = get_object_vars($obj);
foreach ($vars as $key=>$value) {
    var_dump($key);
    var_dump($value);
}
print_r($vars);
yt_debug_print_break_line();


/***************** get_parent_class ********************/
DebugUtil::printDebugSeperator("get_parent_class");
$obj = new MyTestExistSubClass();
$parentClass = get_parent_class($obj);
var_dump($parentClass);
yt_debug_print_break_line();



/***************** get_parent_class ********************/
DebugUtil::printDebugSeperator("get_parent_class");
$obj = new MyTestExistSubClass();
$isA = is_a($obj, "MyTestExistClass");
echo "\$isA MyTestExistClass = $isA  <br/>\r\n";
$isA = is_a($obj, "MyTestExistSubClass");
echo "\$isA MyTestExistSubClass = $isA  <br/>\r\n";
$isA = is_a($obj, "MyTestUnExistSubClass");
echo "\$isA MyTestUnExistSubClass = $isA  <br/>\r\n";
yt_debug_print_break_line();


/***************** method_exists ********************/
DebugUtil::printDebugSeperator("method_exists");
$obj = new MyTestExistSubClass();
$methodExists = method_exists($obj, "existMethod");
echo "existMethod exists = $methodExists  <br/>\r\n";
$methodExists = method_exists($obj, "unExistMethod");
echo "unExistMethod exists = $methodExists  <br/>\r\n";
yt_debug_print_break_line();


/***************** property_exists ********************/
DebugUtil::printDebugSeperator("property_exists");
$propExists = property_exists($obj, "var1");
echo "var1 exists = $propExists  <br/>\r\n";
$propExists = property_exists($obj, "pri_var2");
echo "pri_var2 exists = $propExists  <br/>\r\n";